import EventManager from "../common/EventManager";
import GameData from "../common/GameData";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SetPrefab extends cc.Component {
    @property(cc.Node)
    btnbind: cc.Node = null;

    start() {
        this.btnbind.active = GameData.gamePlayerData.needBinding || false;
    }

    
    /**
     * 切换账号
     */
    onClickChangeLog() {
        this.onEventEmit("\n======>切换账号unionlogin(true):");
        let res = jsb.reflection.callStaticMethod(false, "entry/src/main/ets/KitMessageHandle", "entry/unionlogin", "true");
        this.onEventEmit(">:unionlogin " + res);
        this.node.destroy();
    }

    /**
     * 取消授权
     */
    onClickLogOut() {
        this.onEventEmit("\n======>取消授权:");
        let res = jsb.reflection.callStaticMethod(false, "entry/src/main/ets/KitMessageHandle", "entry/logout", "");
        this.onEventEmit(">:logout " + res);
        this.node.destroy();
    }

    /**
     * 解绑
     */
    onClickUnbind() {
        this.onEventEmit("\n======>解绑:");
        let res = jsb.reflection.callStaticMethod(false, "entry/src/main/ets/KitMessageHandle", "entry/onUnbind", JSON.stringify(GameData.gamePlayerData));
        this.onEventEmit(">:onUnbind " + res);
        this.node.destroy();
    }

    /**
     * 发送数据
     * @param e 数据
     */
    onEventEmit(e: string) {
        EventManager.emit(EventManager.OUTPUT_CONTENT_CHANGE, e);
    }

    onClickClose() {
        this.node.destroy();
    }
}
